// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.16.10
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// SysTenantPackageUpdateFields 修改租户套餐字段过滤
type SysTenantPackageUpdateFields struct {
	Name      string `json:"name"      dc:"套餐名"`
	Status    int    `json:"status"    dc:"租户状态"`
	Remark    string `json:"remark"    dc:"备注"`
	MenuIds   string `json:"menuIds"   dc:"关联的菜单编号"`
	UpdatedBy int64  `json:"updatedBy" dc:"更新者"`
}

// SysTenantPackageInsertFields 新增租户套餐字段过滤
type SysTenantPackageInsertFields struct {
	Name      string `json:"name"      dc:"套餐名"`
	Status    int    `json:"status"    dc:"租户状态"`
	Remark    string `json:"remark"    dc:"备注"`
	MenuIds   string `json:"menuIds"   dc:"关联的菜单编号"`
	CreatedBy int64  `json:"createdBy" dc:"创建者"`
}

// SysTenantPackageEditInp 修改/新增租户套餐
type SysTenantPackageEditInp struct {
	entity.SysTenantPackage
}

func (in *SysTenantPackageEditInp) Filter(ctx context.Context) (err error) {
	// 验证套餐名
	if err := g.Validator().Rules("required").Data(in.Name).Messages("套餐名不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证租户状态
	if err := g.Validator().Rules("required").Data(in.Status).Messages("租户状态不能为空").Run(ctx); err != nil {
		return err.Current()
	}
	if err := g.Validator().Rules("in:1,2").Data(in.Status).Messages("租户状态值不正确").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证关联的菜单编号
	if err := g.Validator().Rules("required").Data(in.MenuIds).Messages("关联的菜单编号不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type SysTenantPackageEditModel struct{}

// SysTenantPackageDeleteInp 删除租户套餐
type SysTenantPackageDeleteInp struct {
	Id interface{} `json:"id" v:"required#套餐编号不能为空" dc:"套餐编号"`
}

func (in *SysTenantPackageDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantPackageDeleteModel struct{}

// SysTenantPackageViewInp 获取指定租户套餐信息
type SysTenantPackageViewInp struct {
	Id int64 `json:"id" v:"required#套餐编号不能为空" dc:"套餐编号"`
}

func (in *SysTenantPackageViewInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantPackageViewModel struct {
	entity.SysTenantPackage
}

// SysTenantPackageListInp 获取租户套餐列表
type SysTenantPackageListInp struct {
	form.PageReq
	Name      string        `json:"name"      dc:"套餐名"`
	Status    int           `json:"status"    dc:"租户状态"`
	CreatedAt []*gtime.Time `json:"createdAt" dc:"创建时间"`
}

func (in *SysTenantPackageListInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantPackageListModel struct {
	Id        int64       `json:"id"        dc:"套餐编号"`
	Name      string      `json:"name"      dc:"套餐名"`
	Status    int         `json:"status"    dc:"租户状态"`
	CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
}

// SysTenantPackageExportModel 导出租户套餐
type SysTenantPackageExportModel struct {
	Id        int64       `json:"id"        dc:"套餐编号"`
	Name      string      `json:"name"      dc:"套餐名"`
	Status    int         `json:"status"    dc:"租户状态"`
	Remark    string      `json:"remark"    dc:"备注"`
	CreatedBy int64       `json:"createdBy" dc:"创建者"`
	CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
	UpdatedBy int64       `json:"updatedBy" dc:"更新者"`
	UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"`
}

// SysTenantPackageStatusInp 更新租户套餐状态
type SysTenantPackageStatusInp struct {
	Id     int64 `json:"id" v:"required#套餐编号不能为空" dc:"套餐编号"`
	Status int   `json:"status" dc:"状态"`
}

func (in *SysTenantPackageStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("套餐编号不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type SysTenantPackageStatusModel struct{}